package com.sharp.core.graphics;

import com.sharp.core.utils.Util;

public class UnColor {
	
	
	public static final UnColor BLACK = new UnColor(0, 0, 0);
	public static final UnColor RED = new UnColor(1, 0, 0);
	public static final UnColor BLUE = new UnColor(0, 0, 1);
	public static final UnColor GREEN = new UnColor(0, 1, 0);
	public static final UnColor WHITE = new UnColor(1, 1, 1);
	public static final UnColor YELLOW = new UnColor(1, 1, 0);
	
	protected float r;
	protected float g;
	protected float b;
	protected float a;
	
	private void setTo(float r, float g, float b) {
		this.r = r;
		this.g = g;
		this.b = b;
	}
	
	private void setTo(UnColor color) {
		this.setTo(color.r, color.g, color.b, color.a);
	}
	
	private void setTo(float r, float g, float b, float a) {
		setTo(r, g, b);
		this.a = a;
	}
	
	public UnColor() {
		r = g = b = a = 1;
	}
	

	
	public UnColor(byte r, byte g, byte b) {
		setTo(	Util.unsignedByteToInt(r)/255.0f,
				Util.unsignedByteToInt(g)/255.0f,
				Util.unsignedByteToInt(b)/255.0f);
	}
	
	
	public UnColor(UnColor c) {
		setTo(c);
	}
	
	public UnColor(float r, float g, float b) {
		setTo(r, g, b);
	}
	
	public final float getR() {
		return r;
	}

	public final float getG() {
		return g;
	}

	public final float getB() {
		return b;
	}

	public final float getA() {
		return a;
	}

	
	@Override
	public String toString() {
	    return "(" + r + ", "+ g + ", " + b + ")";
	}

	public final int intValue() {
		int r = (int) (this.r*255);
		int g = (int) (this.g*255);
		int b = (int) (this.b*255);
		int a = (int) (this.a*255);
		return (r<<24) | (g<<16) | (b<<8) | a;
	}
}
